﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Text;

namespace T.FAS.Runtime.Metadata.Dao
{
    public class EnvironmentManager
    {
        private static readonly string s_curEnvironment = ConfigurationManager.AppSettings["FASEnvironment"];
        private static EnvironmentType s_curEnvironmentType = EnvironmentType.None;

        public static string CurrentEnvironment
        {
            get
            {
                if (s_curEnvironmentType == EnvironmentType.None)
                {
                    try
                    {
                        if (!string.IsNullOrEmpty(s_curEnvironment))
                        {
                            if (int.TryParse(s_curEnvironment, out int intVal))
                            {
                                s_curEnvironmentType = (EnvironmentType)intVal;
                            }
                            else
                            {
                                s_curEnvironmentType = (EnvironmentType)Enum.Parse(typeof(EnvironmentType), s_curEnvironment);
                            }
                        }
                        else
                        {
                            s_curEnvironmentType = EnvironmentType.RTP;
                        }
                    }
                    catch
                    {
                        s_curEnvironmentType = EnvironmentType.RTP;
                    }
                }
                return s_curEnvironmentType.ToString();
            }
        }

        private EnvironmentManager() { }
    }

    public enum EnvironmentType
    {
        None = -1,
        RTP = 0,
        Release = 1,
        Dev = 2,
    }
}
